﻿using System.Linq;
using QFramework;

namespace Gp.Scripts.Core {
    public class InventoryModel : PersistentModel<SerializedInventoryModel> {
        private const int DefaultInventoryCapacity = 24;
        public PlayerInventory PlayerInventory { get; set; }

        public SerializedInventoryModel SerializedInventoryModel { get; private set; } = new();


        protected override void OnInit() { }


        public bool CheckInventory(string inventoryName, string characterName) {
            if (inventoryName.IsNullOrEmpty() || characterName.IsNullOrEmpty()) return false;
            // playerName 必须是存在的角色名称
            return Global.Get<ConversationSystem>().HasCharacter(characterName);
        }


        public override ISerializedModel OnSave() {
            SerializedInventoryModel data = new();

            // foreach (var obj in Inventory.RegisteredInventories) {
            //     if (obj is not BaseInventory {IsDirty: true} inventory) continue;
            //
            //     data.inventories.Add(inventory.SerializedData());
            // }

            return data;
        }


        protected override void OnLoad(SerializedInventoryModel data) {
            SerializedInventoryModel = data;
        }

    }
}